<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<!-- /fasttmp/mkdist-qt-4.3.5-1211793125/qtopia-core-opensource-src-4.3.5/src/gui/widgets/qmenu.cpp -->
<head>
  <title>Qt 4.3: QMenu Class Reference</title>
  <link href="classic.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td align="left" valign="top" width="32"><a href="http://www.trolltech.com/products/qt"><img src="images/qt-logo.png" align="left" width="32" height="32" border="0" /></a></td>
<td width="1">&nbsp;&nbsp;</td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a>&nbsp;&middot; <a href="classes.html"><font color="#004faf">All&nbsp;Classes</font></a>&nbsp;&middot; <a href="mainclasses.html"><font color="#004faf">Main&nbsp;Classes</font></a>&nbsp;&middot; <a href="groups.html"><font color="#004faf">Grouped&nbsp;Classes</font></a>&nbsp;&middot; <a href="modules.html"><font color="#004faf">Modules</font></a>&nbsp;&middot; <a href="functions.html"><font color="#004faf">Functions</font></a></td>
<td align="right" valign="top" width="230"><a href="http://www.trolltech.com"><img src="images/trolltech-logo.png" align="right" width="203" height="32" border="0" /></a></td></tr></table><h1 align="center">QMenu Class Reference<br /><sup><sup>[<a href="qtgui.html">QtGui</a> module]</sup></sup></h1>
<p>The QMenu class provides a menu widget for use in menu bars, context menus, and other popup menus. <a href="#details">More...</a></p>
<pre> #include &lt;QMenu&gt;</pre><p>Inherits <a href="qwidget.html">QWidget</a>.</p>
<p>Inherited by <a href="q3popupmenu.html">Q3PopupMenu</a>.</p>
<ul>
<li><a href="qmenu-members.html">List of all members, including inherited members</a></li>
<li><a href="qmenu-qt3.html">Qt 3 support members</a></li>
</ul>
<a name="properties"></a>
<h3>Properties</h3>
<ul>
<li><div class="fn"/><b><a href="qmenu.html#icon-prop">icon</a></b> : QIcon</li>
<li><div class="fn"/><b><a href="qmenu.html#separatorsCollapsible-prop">separatorsCollapsible</a></b> : bool</li>
<li><div class="fn"/><b><a href="qmenu.html#tearOffEnabled-prop">tearOffEnabled</a></b> : bool</li>
<li><div class="fn"/><b><a href="qmenu.html#title-prop">title</a></b> : QString</li>
</ul>
<ul>
<li><div class="fn"/>56 properties inherited from <a href="qwidget.html#properties">QWidget</a></li>
<li><div class="fn"/>1 property inherited from <a href="qobject.html#properties">QObject</a></li>
</ul>
<a name="public-functions"></a>
<h3>Public Functions</h3>
<ul>
<li><div class="fn"/><b><a href="qmenu.html#QMenu">QMenu</a></b> ( QWidget * <i>parent</i> = 0 )</li>
<li><div class="fn"/><b><a href="qmenu.html#QMenu-2">QMenu</a></b> ( const QString &amp; <i>title</i>, QWidget * <i>parent</i> = 0 )</li>
<li><div class="fn"/><b><a href="qmenu.html#dtor.QMenu">~QMenu</a></b> ()</li>
<li><div class="fn"/>QAction * <b><a href="qmenu.html#actionAt">actionAt</a></b> ( const QPoint &amp; <i>pt</i> ) const</li>
<li><div class="fn"/>QRect <b><a href="qmenu.html#actionGeometry">actionGeometry</a></b> ( QAction * <i>act</i> ) const</li>
<li><div class="fn"/>QAction * <b><a href="qmenu.html#activeAction">activeAction</a></b> () const</li>
<li><div class="fn"/>QAction * <b><a href="qmenu.html#addAction">addAction</a></b> ( const QString &amp; <i>text</i> )</li>
<li><div class="fn"/>QAction * <b><a href="qmenu.html#addAction-2">addAction</a></b> ( const QIcon &amp; <i>icon</i>, const QString &amp; <i>text</i> )</li>
<li><div class="fn"/>QAction * <b><a href="qmenu.html#addAction-3">addAction</a></b> ( const QString &amp; <i>text</i>, const QObject * <i>receiver</i>, const char * <i>member</i>, const QKeySequence &amp; <i>shortcut</i> = 0 )</li>
<li><div class="fn"/>QAction * <b><a href="qmenu.html#addAction-4">addAction</a></b> ( const QIcon &amp; <i>icon</i>, const QString &amp; <i>text</i>, const QObject * <i>receiver</i>, const char * <i>member</i>, const QKeySequence &amp; <i>shortcut</i> = 0 )</li>
<li><div class="fn"/>void <b><a href="qmenu.html#addAction-5">addAction</a></b> ( QAction * <i>action</i> )</li>
<li><div class="fn"/>QAction * <b><a href="qmenu.html#addMenu">addMenu</a></b> ( QMenu * <i>menu</i> )</li>
<li><div class="fn"/>QMenu * <b><a href="qmenu.html#addMenu-2">addMenu</a></b> ( const QString &amp; <i>title</i> )</li>
<li><div class="fn"/>QMenu * <b><a href="qmenu.html#addMenu-3">addMenu</a></b> ( const QIcon &amp; <i>icon</i>, const QString &amp; <i>title</i> )</li>
<li><div class="fn"/>QAction * <b><a href="qmenu.html#addSeparator">addSeparator</a></b> ()</li>
<li><div class="fn"/>void <b><a href="qmenu.html#clear">clear</a></b> ()</li>
<li><div class="fn"/>QAction * <b><a href="qmenu.html#defaultAction">defaultAction</a></b> () const</li>
<li><div class="fn"/>QAction * <b><a href="qmenu.html#exec">exec</a></b> ()</li>
<li><div class="fn"/>QAction * <b><a href="qmenu.html#exec-2">exec</a></b> ( const QPoint &amp; <i>p</i>, QAction * <i>action</i> = 0 )</li>
<li><div class="fn"/>void <b><a href="qmenu.html#hideTearOffMenu">hideTearOffMenu</a></b> ()</li>
<li><div class="fn"/>QIcon <b><a href="qmenu.html#icon-prop">icon</a></b> () const</li>
<li><div class="fn"/>QAction * <b><a href="qmenu.html#insertMenu">insertMenu</a></b> ( QAction * <i>before</i>, QMenu * <i>menu</i> )</li>
<li><div class="fn"/>QAction * <b><a href="qmenu.html#insertSeparator">insertSeparator</a></b> ( QAction * <i>before</i> )</li>
<li><div class="fn"/>bool <b><a href="qmenu.html#isEmpty">isEmpty</a></b> () const</li>
<li><div class="fn"/>bool <b><a href="qmenu.html#tearOffEnabled-prop">isTearOffEnabled</a></b> () const</li>
<li><div class="fn"/>bool <b><a href="qmenu.html#isTearOffMenuVisible">isTearOffMenuVisible</a></b> () const</li>
<li><div class="fn"/>QAction * <b><a href="qmenu.html#menuAction">menuAction</a></b> () const</li>
<li><div class="fn"/>void <b><a href="qmenu.html#popup">popup</a></b> ( const QPoint &amp; <i>p</i>, QAction * <i>atAction</i> = 0 )</li>
<li><div class="fn"/>bool <b><a href="qmenu.html#separatorsCollapsible-prop">separatorsCollapsible</a></b> () const</li>
<li><div class="fn"/>void <b><a href="qmenu.html#setActiveAction">setActiveAction</a></b> ( QAction * <i>act</i> )</li>
<li><div class="fn"/>void <b><a href="qmenu.html#setDefaultAction">setDefaultAction</a></b> ( QAction * <i>act</i> )</li>
<li><div class="fn"/>void <b><a href="qmenu.html#icon-prop">setIcon</a></b> ( const QIcon &amp; <i>icon</i> )</li>
<li><div class="fn"/>void <b><a href="qmenu.html#separatorsCollapsible-prop">setSeparatorsCollapsible</a></b> ( bool <i>collapse</i> )</li>
<li><div class="fn"/>void <b><a href="qmenu.html#tearOffEnabled-prop">setTearOffEnabled</a></b> ( bool )</li>
<li><div class="fn"/>void <b><a href="qmenu.html#title-prop">setTitle</a></b> ( const QString &amp; <i>title</i> )</li>
<li><div class="fn"/>QString <b><a href="qmenu.html#title-prop">title</a></b> () const</li>
</ul>
<ul>
<li><div class="fn"/>201 public functions inherited from <a href="qwidget.html#public-functions">QWidget</a></li>
<li><div class="fn"/>29 public functions inherited from <a href="qobject.html#public-functions">QObject</a></li>
<li><div class="fn"/>12 public functions inherited from <a href="qpaintdevice.html#public-functions">QPaintDevice</a></li>
</ul>
<a name="signals"></a>
<h3>Signals</h3>
<ul>
<li><div class="fn"/>void <b><a href="qmenu.html#aboutToHide">aboutToHide</a></b> ()</li>
<li><div class="fn"/>void <b><a href="qmenu.html#aboutToShow">aboutToShow</a></b> ()</li>
<li><div class="fn"/>void <b><a href="qmenu.html#hovered">hovered</a></b> ( QAction * <i>action</i> )</li>
<li><div class="fn"/>void <b><a href="qmenu.html#triggered">triggered</a></b> ( QAction * <i>action</i> )</li>
</ul>
<ul>
<li><div class="fn"/>1 signal inherited from <a href="qwidget.html#signals">QWidget</a></li>
<li><div class="fn"/>1 signal inherited from <a href="qobject.html#signals">QObject</a></li>
</ul>
<a name="static-public-members"></a>
<h3>Static Public Members</h3>
<ul>
<li><div class="fn"/>QAction * <b><a href="qmenu.html#exec-3">exec</a></b> ( QList&lt;QAction *&gt; <i>actions</i>, const QPoint &amp; <i>pos</i>, QAction * <i>at</i> = 0 )</li>
</ul>
<ul>
<li><div class="fn"/>4 static public members inherited from <a href="qwidget.html#static-public-members">QWidget</a></li>
<li><div class="fn"/>5 static public members inherited from <a href="qobject.html#static-public-members">QObject</a></li>
</ul>
<a name="protected-functions"></a>
<h3>Protected Functions</h3>
<ul>
<li><div class="fn"/>int <b><a href="qmenu.html#columnCount">columnCount</a></b> () const</li>
<li><div class="fn"/>void <b><a href="qmenu.html#initStyleOption">initStyleOption</a></b> ( QStyleOptionMenuItem * <i>option</i>, const QAction * <i>action</i> ) const</li>
</ul>
<ul>
<li><div class="fn"/>38 protected functions inherited from <a href="qwidget.html#protected-functions">QWidget</a></li>
<li><div class="fn"/>7 protected functions inherited from <a href="qobject.html#protected-functions">QObject</a></li>
<li><div class="fn"/>1 protected function inherited from <a href="qpaintdevice.html#protected-functions">QPaintDevice</a></li>
</ul>
<h3>Additional Inherited Members</h3>
<ul>
<li><div class="fn"/>19 public slots inherited from <a href="qwidget.html#public-slots">QWidget</a></li>
<li><div class="fn"/>1 public slot inherited from <a href="qobject.html#public-slots">QObject</a></li>
<li><div class="fn"/>1 protected slot inherited from <a href="qwidget.html#protected-slots">QWidget</a></li>
</ul>
<a name="details"></a>
<hr />
<h2>Detailed Description</h2>
<p>The QMenu class provides a menu widget for use in menu bars, context menus, and other popup menus.</p>
<p>A menu widget is a selection menu. It can be either a pull-down menu in a menu bar or a standalone context menu. Pull-down menus are shown by the menu bar when the user clicks on the respective item or presses the specified shortcut key. Use <a href="qmenubar.html#addMenu">QMenuBar::addMenu</a>() to insert a menu into a menu bar. Context menus are usually invoked by some special keyboard key or by right-clicking. They can be executed either asynchronously with <a href="qmenu.html#popup">popup</a>() or synchronously with <a href="qmenu.html#exec">exec</a>(). Menus can also be invoked in response to button presses; these are just like context menus except for how they are invoked.</p>
    <table align="center" cellpadding="0">
    <tr>
        <td>
            <p><img src="images/plastique-menu.png" /></p>
        </td>
        <td>
            <p><img src="images/windowsxp-menu.png" /></p>
        </td>
        <td>
            <p><img src="images/macintosh-menu.png" /></p>
        </td>

    </tr>
    <tr>
        <td colspan="3">
           <p>A menu shown in <a href="gallery-plastique.html">Plastique widget style</a>, <a href="gallery-windowsxp.html">Windows XP widget style</a>, and <a href="gallery-macintosh.html">Macintosh widget style</a>.</p>
        </td>
    </tr>
    </table>
    <p>A menu consists of a list of action items. Actions are added with <a href="qmenu.html#addAction">addAction</a>(). An action is represented vertically and rendered by <a href="qstyle.html">QStyle</a>. In addition, actions can have a text label, an optional icon drawn on the very left side, and shortcut key sequence such as &quot;Ctrl+X&quot;.</p>
<p>There are three kinds of action items: separators, actions that show a submenu, and actions that perform an action. Separators are inserted with <a href="qmenu.html#addSeparator">addSeparator</a>(). For submenus use <a href="qmenu.html#addMenu">addMenu</a>(). All other items are considered action items.</p>
<p>When inserting action items you usually specify a receiver and a slot. The receiver will be notifed whenever the item is <a href="qaction.html#triggered">triggered()</a>. In addition, QMenu provides two signals, <a href="qmenu-qt3.html#activated">activated</a>() and <a href="qmenu-qt3.html#highlighted">highlighted</a>(), which signal the <a href="qaction.html">QAction</a> that was triggered from the menu.</p>
<p>You clear a menu with <a href="qmenu.html#clear">clear</a>() and remove individual action items with <a href="qwidget.html#removeAction">removeAction</a>().</p>
<p>A QMenu can also provide a tear-off menu. A tear-off menu is a top-level window that contains a copy of the menu. This makes it possible for the user to &quot;tear off&quot; frequently used menus and position them in a convenient place on the screen. If you want this functionality for a particular menu, insert a tear-off handle with <a href="qmenu.html#tearOffEnabled-prop">setTearOffEnabled</a>(). When using tear-off menus, bear in mind that the concept isn't typically used on Microsoft Windows so some users may not be familiar with it. Consider using a <a href="qtoolbar.html">QToolBar</a> instead.</p>
<p>See the <a href="mainwindows-menus.html">Menus</a> example for an example of how to use <a href="qmenubar.html">QMenuBar</a> and QMenu in your application.</p>
<p>Important inherited functions: <a href="qmenu.html#addAction">addAction</a>(), <a href="qwidget.html#removeAction">removeAction</a>(), <a href="qmenu.html#clear">clear</a>(), <a href="qmenu.html#addSeparator">addSeparator</a>(), and <a href="qmenu.html#addMenu">addMenu</a>().</p>
<p>See also <a href="qmenubar.html">QMenuBar</a>, <a href="guibooks.html#fowler">GUI Design Handbook: Menu, Drop-Down and Pop-Up</a>, <a href="mainwindows-application.html">Application Example</a>, <a href="mainwindows-menus.html">Menus Example</a>, and <a href="mainwindows-recentfiles.html">Recent Files Example</a>.</p>
<hr />
<h2>Property Documentation</h2>
<h3 class="fn"><a name="icon-prop"></a>icon : <a href="qicon.html">QIcon</a></h3>
<p>This property holds the icon of the menu.</p>
<p>This is equivalent to the <a href="qaction.html#icon-prop">QAction::icon</a> property of the <a href="qmenu.html#menuAction">menuAction</a>().</p>
<p>Access functions:</p>
<ul>
<li><div class="fn"/><b>QIcon icon () const</b></li>
<li><div class="fn"/><b>void setIcon ( const QIcon &amp; <i>icon</i> )</b></li>
</ul>
<h3 class="fn"><a name="separatorsCollapsible-prop"></a>separatorsCollapsible : bool</h3>
<p>This property holds whether consecutive separators should be collapsed.</p>
<p>This property specifies whether consecutive separators in the menu should be visually collapsed to a single one. Separators at the beginning or the end of the menu are also hidden.</p>
<p>This property was introduced in Qt 4.2.</p>
<p>Access functions:</p>
<ul>
<li><div class="fn"/><b>bool separatorsCollapsible () const</b></li>
<li><div class="fn"/><b>void setSeparatorsCollapsible ( bool <i>collapse</i> )</b></li>
</ul>
<h3 class="fn"><a name="tearOffEnabled-prop"></a>tearOffEnabled : bool</h3>
<p>This property holds whether the menu supports being torn off.</p>
<p>When true, <a href="qmenu.html">QMenu</a> has a special menu item (often shown as a dashed line at the top of the menu) that creates a copy of the menu when the tear-off menu item is triggered. This &quot;torn-off&quot; copy lives in a separate window. It contains the same menu items as the original menu, with the exception of the tear-off handle.</p>
<p>Access functions:</p>
<ul>
<li><div class="fn"/><b>bool isTearOffEnabled () const</b></li>
<li><div class="fn"/><b>void setTearOffEnabled ( bool )</b></li>
</ul>
<h3 class="fn"><a name="title-prop"></a>title : <a href="qstring.html">QString</a></h3>
<p>This property holds the title of the menu.</p>
<p>This is equivalent to the <a href="qaction.html#text-prop">QAction::text</a> property of the <a href="qmenu.html#menuAction">menuAction</a>().</p>
<p>Access functions:</p>
<ul>
<li><div class="fn"/><b>QString title () const</b></li>
<li><div class="fn"/><b>void setTitle ( const QString &amp; <i>title</i> )</b></li>
</ul>
<hr />
<h2>Member Function Documentation</h2>
<h3 class="fn"><a name="QMenu"></a>QMenu::QMenu ( <a href="qwidget.html">QWidget</a> * <i>parent</i> = 0 )</h3>
<p>Constructs a menu with parent <i>parent</i>.</p>
<p>Although a popup menu is always a top-level widget, if a parent is passed the popup menu will be deleted when that parent is destroyed (as with any other <a href="qobject.html">QObject</a>).</p>
<h3 class="fn"><a name="QMenu-2"></a>QMenu::QMenu ( const <a href="qstring.html">QString</a> &amp; <i>title</i>, <a href="qwidget.html">QWidget</a> * <i>parent</i> = 0 )</h3>
<p>Constructs a menu with a <i>title</i> and a <i>parent</i>.</p>
<p>Although a popup menu is always a top-level widget, if a parent is passed the popup menu will be deleted when that parent is destroyed (as with any other <a href="qobject.html">QObject</a>).</p>
<p>See also <a href="qmenu.html#title-prop">title</a>.</p>
<h3 class="fn"><a name="dtor.QMenu"></a>QMenu::~QMenu ()</h3>
<p>Destroys the menu.</p>
<h3 class="fn"><a name="aboutToHide"></a>void QMenu::aboutToHide ()&nbsp;&nbsp;<tt> [signal]</tt></h3>
<p>This signal is emitted just before the menu is hidden from the user.</p>
<p>This function was introduced in Qt 4.2.</p>
<p>See also <a href="qmenu.html#aboutToShow">aboutToShow</a>() and <a href="qwidget.html#hide">hide</a>().</p>
<h3 class="fn"><a name="aboutToShow"></a>void QMenu::aboutToShow ()&nbsp;&nbsp;<tt> [signal]</tt></h3>
<p>This signal is emitted just before the menu is shown to the user.</p>
<p>See also <a href="qmenu.html#aboutToHide">aboutToHide</a>() and <a href="qwidget.html#show">show</a>().</p>
<h3 class="fn"><a name="actionAt"></a><a href="qaction.html">QAction</a> * QMenu::actionAt ( const <a href="qpoint.html">QPoint</a> &amp; <i>pt</i> ) const</h3>
<p>Returns the item at <i>pt</i>; returns 0 if there is no item there.</p>
<h3 class="fn"><a name="actionGeometry"></a><a href="qrect.html">QRect</a> QMenu::actionGeometry ( <a href="qaction.html">QAction</a> * <i>act</i> ) const</h3>
<p>Returns the geometry of action <i>act</i>.</p>
<h3 class="fn"><a name="activeAction"></a><a href="qaction.html">QAction</a> * QMenu::activeAction () const</h3>
<p>Returns the currently highlighted action, or 0 if no action is currently highlighted.</p>
<p>See also <a href="qmenu.html#setActiveAction">setActiveAction</a>().</p>
<h3 class="fn"><a name="addAction"></a><a href="qaction.html">QAction</a> * QMenu::addAction ( const <a href="qstring.html">QString</a> &amp; <i>text</i> )</h3>
<p>This convenience function creates a new action with <i>text</i>. The function adds the newly created action to the menu's list of actions, and returns it.</p>
<p>See also <a href="qwidget.html#addAction">QWidget::addAction</a>().</p>
<h3 class="fn"><a name="addAction-2"></a><a href="qaction.html">QAction</a> * QMenu::addAction ( const <a href="qicon.html">QIcon</a> &amp; <i>icon</i>, const <a href="qstring.html">QString</a> &amp; <i>text</i> )</h3>
<p>This is an overloaded member function, provided for convenience.</p>
<p>This convenience function creates a new action with an <i>icon</i> and some <i>text</i>. The function adds the newly created action to the menu's list of actions, and returns it.</p>
<p>See also <a href="qwidget.html#addAction">QWidget::addAction</a>().</p>
<h3 class="fn"><a name="addAction-3"></a><a href="qaction.html">QAction</a> * QMenu::addAction ( const <a href="qstring.html">QString</a> &amp; <i>text</i>, const <a href="qobject.html">QObject</a> * <i>receiver</i>, const char * <i>member</i>, const <a href="qkeysequence.html">QKeySequence</a> &amp; <i>shortcut</i> = 0 )</h3>
<p>This is an overloaded member function, provided for convenience.</p>
<p>This convenience function creates a new action with the text <i>text</i> and an optional shortcut <i>shortcut</i>. The action's <a href="qaction.html#triggered">triggered()</a> signal is connected to the <i>receiver</i>'s <i>member</i> slot. The function adds the newly created action to the menu's list of actions and returns it.</p>
<p>See also <a href="qwidget.html#addAction">QWidget::addAction</a>().</p>
<h3 class="fn"><a name="addAction-4"></a><a href="qaction.html">QAction</a> * QMenu::addAction ( const <a href="qicon.html">QIcon</a> &amp; <i>icon</i>, const <a href="qstring.html">QString</a> &amp; <i>text</i>, const <a href="qobject.html">QObject</a> * <i>receiver</i>, const char * <i>member</i>, const <a href="qkeysequence.html">QKeySequence</a> &amp; <i>shortcut</i> = 0 )</h3>
<p>This is an overloaded member function, provided for convenience.</p>
<p>This convenience function creates a new action with an <i>icon</i> and some <i>text</i> and an optional shortcut <i>shortcut</i>. The action's <a href="qaction.html#triggered">triggered()</a> signal is connected to the <i>member</i> slot of the <i>receiver</i> object. The function adds the newly created action to the menu's list of actions, and returns it.</p>
<p>See also <a href="qwidget.html#addAction">QWidget::addAction</a>().</p>
<h3 class="fn"><a name="addAction-5"></a>void QMenu::addAction ( <a href="qaction.html">QAction</a> * <i>action</i> )</h3>
<p>This is an overloaded member function, provided for convenience.</p>
<p>Appends the action <i>action</i> to the menu's list of actions.</p>
<p>See also <a href="qmenubar.html#addAction">QMenuBar::addAction</a>() and <a href="qwidget.html#addAction">QWidget::addAction</a>().</p>
<h3 class="fn"><a name="addMenu"></a><a href="qaction.html">QAction</a> * QMenu::addMenu ( QMenu * <i>menu</i> )</h3>
<p>This convenience function adds <i>menu</i> as a submenu to this menu. It returns the menus <a href="qmenu.html#menuAction">menuAction</a>().</p>
<p>See also <a href="qwidget.html#addAction">QWidget::addAction</a>() and <a href="qmenu.html#menuAction">QMenu::menuAction</a>().</p>
<h3 class="fn"><a name="addMenu-2"></a>QMenu * QMenu::addMenu ( const <a href="qstring.html">QString</a> &amp; <i>title</i> )</h3>
<p>This is an overloaded member function, provided for convenience.</p>
<p>Appends a new <a href="qmenu.html">QMenu</a> with <i>title</i> to the menu. The menu takes ownership of the menu. Returns the new menu.</p>
<p>See also <a href="qwidget.html#addAction">QWidget::addAction</a>() and <a href="qmenu.html#menuAction">QMenu::menuAction</a>().</p>
<h3 class="fn"><a name="addMenu-3"></a>QMenu * QMenu::addMenu ( const <a href="qicon.html">QIcon</a> &amp; <i>icon</i>, const <a href="qstring.html">QString</a> &amp; <i>title</i> )</h3>
<p>This is an overloaded member function, provided for convenience.</p>
<p>Appends a new <a href="qmenu.html">QMenu</a> with <i>icon</i> and <i>title</i> to the menu. The menu takes ownership of the menu. Returns the new menu.</p>
<p>See also <a href="qwidget.html#addAction">QWidget::addAction</a>() and <a href="qmenu.html#menuAction">QMenu::menuAction</a>().</p>
<h3 class="fn"><a name="addSeparator"></a><a href="qaction.html">QAction</a> * QMenu::addSeparator ()</h3>
<p>This convenience function creates a new separator action, i.e&#x2e; an action with <a href="qaction.html#isSeparator">QAction::isSeparator</a>() returning true, and adds the new action to this menu's list of actions. It returns the newly created action.</p>
<p>See also <a href="qwidget.html#addAction">QWidget::addAction</a>().</p>
<h3 class="fn"><a name="clear"></a>void QMenu::clear ()</h3>
<p>Removes all the menu's actions. Actions owned by the menu and not shown in any other widget are deleted.</p>
<p>See also <a href="qwidget.html#removeAction">removeAction</a>().</p>
<h3 class="fn"><a name="columnCount"></a>int QMenu::columnCount () const&nbsp;&nbsp;<tt> [protected]</tt></h3>
<p>If a menu does not fit on the screen it lays itself out so that it does fit. It is style dependent what layout means (for example, on Windows it will use multiple columns).</p>
<p>This functions returns the number of columns necessary.</p>
<h3 class="fn"><a name="defaultAction"></a><a href="qaction.html">QAction</a> * QMenu::defaultAction () const</h3>
<p>Returns the current default action.</p>
<p>See also <a href="qmenu.html#setDefaultAction">setDefaultAction</a>().</p>
<h3 class="fn"><a name="exec"></a><a href="qaction.html">QAction</a> * QMenu::exec ()</h3>
<p>Executes this menu synchronously.</p>
<p>This is equivalent to <tt>exec(pos())</tt>.</p>
<p>This returns the triggered <a href="qaction.html">QAction</a> in either the popup menu or one of its submenus, or 0 if no item was triggered (normally because the user pressed Esc).</p>
<p>In most situations you'll want to specify the position yourself, for example, the current mouse position:</p>
<pre> exec(QCursor::pos());</pre>
<p>or aligned to a widget:</p>
<pre> exec(somewidget.mapToGlobal(QPoint(0,0)));</pre>
<p>or in reaction to a <a href="qmouseevent.html">QMouseEvent</a> *e:</p>
<pre> exec(e-&gt;globalPos());</pre>
<h3 class="fn"><a name="exec-2"></a><a href="qaction.html">QAction</a> * QMenu::exec ( const <a href="qpoint.html">QPoint</a> &amp; <i>p</i>, <a href="qaction.html">QAction</a> * <i>action</i> = 0 )</h3>
<p>This is an overloaded member function, provided for convenience.</p>
<p>Executes this menu synchronously.</p>
<p>Pops up the menu so that the action <i>action</i> will be at the specified <i>global</i> position <i>p</i>. To translate a widget's local coordinates into global coordinates, use <a href="qwidget.html#mapToGlobal">QWidget::mapToGlobal</a>().</p>
<p>This returns the triggered <a href="qaction.html">QAction</a> in either the popup menu or one of its submenus, or 0 if no item was triggered (normally because the user pressed Esc).</p>
<p>Note that all signals are emitted as usual. If you connect a <a href="qaction.html">QAction</a> to a slot and call the menu's <a href="qmenu.html#exec">exec</a>(), you get the result both via the signal-slot connection and in the return value of <a href="qmenu.html#exec">exec</a>().</p>
<p>Common usage is to position the menu at the current mouse position:</p>
<pre> exec(QCursor::pos());</pre>
<p>or aligned to a widget:</p>
<pre> exec(somewidget.mapToGlobal(QPoint(0, 0)));</pre>
<p>or in reaction to a <a href="qmouseevent.html">QMouseEvent</a> *e:</p>
<pre> exec(e-&gt;globalPos());</pre>
<p>When positioning a menu with <a href="qmenu.html#exec">exec</a>() or <a href="qmenu.html#popup">popup</a>(), bear in mind that you cannot rely on the menu's current <a href="qwidget.html#size-prop">size</a>(). For performance reasons, the menu adapts its size only when necessary. So in many cases, the size before and after the show is different. Instead, use <a href="qwidget.html#sizeHint-prop">sizeHint</a>() which calculates the proper size depending on the menu's current contents.</p>
<p>See also <a href="qmenu.html#popup">popup</a>() and <a href="qwidget.html#mapToGlobal">QWidget::mapToGlobal</a>().</p>
<h3 class="fn"><a name="exec-3"></a><a href="qaction.html">QAction</a> * QMenu::exec ( <a href="qlist.html">QList</a>&lt;<a href="qaction.html">QAction</a> *&gt; <i>actions</i>, const <a href="qpoint.html">QPoint</a> &amp; <i>pos</i>, <a href="qaction.html">QAction</a> * <i>at</i> = 0 )&nbsp;&nbsp;<tt> [static]</tt></h3>
<p>This is an overloaded member function, provided for convenience.</p>
<p>Executes this menu synchronously.</p>
<p>The menu's actions are specified by the list of <i>actions</i>. The menu will pop up so that the specified action, <i>at</i>, appears at global position <i>pos</i>. If <i>at</i> is not specified then the menu appears at position <i>pos</i>.</p>
<p>The function returns the triggered <a href="qaction.html">QAction</a> in either the popup menu or one of its submenus, or 0 if no item was triggered (normally because the user pressed Esc).</p>
<p>This is equivalent to:</p>
<pre> QMenu menu;
 QAction *at = actions[0]; <span class="comment">//</span> Assumes actions is not empty
 foreach (QAction *a, actions)
    menu.addAction(a);
 menu.exec(pos, at);</pre>
<p>See also <a href="qmenu.html#popup">popup</a>() and <a href="qwidget.html#mapToGlobal">QWidget::mapToGlobal</a>().</p>
<h3 class="fn"><a name="hideTearOffMenu"></a>void QMenu::hideTearOffMenu ()</h3>
<p>This function will forcibly hide the torn off menu making it disappear from the users desktop.</p>
<p>See also <a href="qmenu.html#isTearOffMenuVisible">isTearOffMenuVisible</a>() and <a href="qmenu.html#tearOffEnabled-prop">isTearOffEnabled</a>().</p>
<h3 class="fn"><a name="hovered"></a>void QMenu::hovered ( <a href="qaction.html">QAction</a> * <i>action</i> )&nbsp;&nbsp;<tt> [signal]</tt></h3>
<p>This signal is emitted when a menu action is highlighted; <i>action</i> is the action that caused the signal to be emitted.</p>
<p>Often this is used to update status information.</p>
<p>See also <a href="qmenu.html#triggered">triggered</a>() and <a href="qaction.html#hovered">QAction::hovered</a>().</p>
<h3 class="fn"><a name="initStyleOption"></a>void QMenu::initStyleOption ( <a href="qstyleoptionmenuitem.html">QStyleOptionMenuItem</a> * <i>option</i>, const <a href="qaction.html">QAction</a> * <i>action</i> ) const&nbsp;&nbsp;<tt> [protected]</tt></h3>
<p>Initialize <i>option</i> with the values from this menu and information from <i>action</i>. This method is useful for subclasses when they need a <a href="qstyleoptionmenuitem.html">QStyleOptionMenuItem</a>, but don't want to fill in all the information themselves.</p>
<p>See also <a href="qstyleoption.html#initFrom">QStyleOption::initFrom</a>() and <a href="qmenubar.html#initStyleOption">QMenuBar::initStyleOption</a>().</p>
<h3 class="fn"><a name="insertMenu"></a><a href="qaction.html">QAction</a> * QMenu::insertMenu ( <a href="qaction.html">QAction</a> * <i>before</i>, QMenu * <i>menu</i> )</h3>
<p>This convenience function inserts <i>menu</i> before action <i>before</i> and returns the menus <a href="qmenu.html#menuAction">menuAction</a>().</p>
<p>See also <a href="qwidget.html#insertAction">QWidget::insertAction</a>() and <a href="qmenu.html#addMenu">addMenu</a>().</p>
<h3 class="fn"><a name="insertSeparator"></a><a href="qaction.html">QAction</a> * QMenu::insertSeparator ( <a href="qaction.html">QAction</a> * <i>before</i> )</h3>
<p>This convenience function creates a new separator action, i.e&#x2e; an action with <a href="qaction.html#isSeparator">QAction::isSeparator</a>() returning true. The function inserts the newly created action into this menu's list of actions before action <i>before</i> and returns it.</p>
<p>See also <a href="qwidget.html#insertAction">QWidget::insertAction</a>() and <a href="qmenu.html#addSeparator">addSeparator</a>().</p>
<h3 class="fn"><a name="isEmpty"></a>bool QMenu::isEmpty () const</h3>
<p>Returns true if there are no actions inserted into the menu, false otherwise.</p>
<p>This function was introduced in Qt 4.2.</p>
<p>See also <a href="qwidget.html#actions">QWidget::actions</a>().</p>
<h3 class="fn"><a name="isTearOffMenuVisible"></a>bool QMenu::isTearOffMenuVisible () const</h3>
<p>When a menu is torn off a second menu is shown to display the menu contents in a new window. When the menu is in this mode and the menu is visible returns true; otherwise false.</p>
<p>See also <a href="qmenu.html#hideTearOffMenu">hideTearOffMenu</a>() and <a href="qmenu.html#tearOffEnabled-prop">isTearOffEnabled</a>().</p>
<h3 class="fn"><a name="menuAction"></a><a href="qaction.html">QAction</a> * QMenu::menuAction () const</h3>
<p>Returns the action associated with this menu.</p>
<h3 class="fn"><a name="popup"></a>void QMenu::popup ( const <a href="qpoint.html">QPoint</a> &amp; <i>p</i>, <a href="qaction.html">QAction</a> * <i>atAction</i> = 0 )</h3>
<p>Displays the menu so that the action <i>atAction</i> will be at the specified <i>global</i> position <i>p</i>. To translate a widget's local coordinates into global coordinates, use <a href="qwidget.html#mapToGlobal">QWidget::mapToGlobal</a>().</p>
<p>When positioning a menu with <a href="qmenu.html#exec">exec</a>() or popup(), bear in mind that you cannot rely on the menu's current <a href="qwidget.html#size-prop">size</a>(). For performance reasons, the menu adapts its size only when necessary, so in many cases, the size before and after the show is different. Instead, use <a href="qwidget.html#sizeHint-prop">sizeHint</a>() which calculates the proper size depending on the menu's current contents.</p>
<p>See also <a href="qwidget.html#mapToGlobal">QWidget::mapToGlobal</a>() and <a href="qmenu.html#exec">exec</a>().</p>
<h3 class="fn"><a name="setActiveAction"></a>void QMenu::setActiveAction ( <a href="qaction.html">QAction</a> * <i>act</i> )</h3>
<p>Sets the currently highlighted action to <i>act</i>.</p>
<p>See also <a href="qmenu.html#activeAction">activeAction</a>().</p>
<h3 class="fn"><a name="setDefaultAction"></a>void QMenu::setDefaultAction ( <a href="qaction.html">QAction</a> * <i>act</i> )</h3>
<p>This will set the default action to <i>act</i>. The default action may have a visual queue depending on the current <a href="qstyle.html">QStyle</a>. A default action is usually meant to indicate what will defaultly happen on a drop, as shown in a context menu.</p>
<p>See also <a href="qmenu.html#defaultAction">defaultAction</a>().</p>
<h3 class="fn"><a name="triggered"></a>void QMenu::triggered ( <a href="qaction.html">QAction</a> * <i>action</i> )&nbsp;&nbsp;<tt> [signal]</tt></h3>
<p>This signal is emitted when an action in this menu is triggered; <i>action</i> is the action that caused the signal to be emitted.</p>
<p>Normally, you connect each menu action's <a href="qaction.html#triggered">triggered()</a> signal to its own custom slot, but sometimes you will want to connect several actions to a single slot, for example, when you have a group of closely related actions, such as &quot;left justify&quot;, &quot;center&quot;, &quot;right justify&quot;.</p>
<p>See also <a href="qmenu.html#hovered">hovered</a>() and <a href="qaction.html#triggered">QAction::triggered</a>().</p>
<p /><address><hr /><div align="center">
<table width="100%" cellspacing="0" border="0"><tr class="address">
<td width="30%">Copyright &copy; 2008 <a href="trolltech.html">Trolltech</a></td>
<td width="40%" align="center"><a href="trademarks.html">Trademarks</a></td>
<td width="30%" align="right"><div align="right">Qt 4.3.5</div></td>
</tr></table></div></address></body>
</html>
